﻿@using SH = EMoney.IStock.Client.Framework.StringHelper;

@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn">
<head>
    <meta name="viewport"content="width=device-width, initial-scale=1"/>
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="@SH.GetStaticFile("IStockClientStatic/ac/css/styleMoblieWhite.css")" id="linkcss" />
    <script src="http://static.emoney.cn/js/libs/jquery.min.1.8.3.js" type="text/javascript"></script>
  
</head>
<body>
    <input id="" style="width:0;height:0;" type="text" style="" class="HiddenBox" autocomplete="off"  maxlength="29" placeholder="" />
    <div id="downmenu" class="HiddenBox" style="left:145px;top:115px;width:415px;"></div>

    <div id="p1" style="margin:0 auto;width:95%;height:90%;margin-top:10%;">
        <table style="width:100%; height:95%;" border="0">
            <tbody>
            <tr style="height:10%;">
                <td class="TitTxt" id="ppmessage" width="20%" style="padding-top:1%;">用户名</td>
                <td colspan="2" style="padding-top:1%;">
                    <input id="account" type="text" style="" class="Blockinput IptW  inputbg1" autocomplete="off"  maxlength="29" placeholder="输入手机或邮箱" />
                </td>
            </tr>
            <tr id="mobilTR" style="height:10%;">
                <td class="TitTxt">&nbsp;</td>
                <td colspan="2" style="padding-top:2%;">
                    <div class="FloatLeft" style="height:100%;width:52%;">
                        <input id="code" type="text" class="Blockinput yzmTxt  inputbg2"  autocomplete="off" maxlength="6" placeholder="输入验证码" />                       
                    </div>
                    <div class="FloatLeft" style="margin-left:10%;width:35%; height:100%;">
                        @*<div id="getCode" class="yzmbtn" >&nbsp;
                            <div style="position:relative;height:1px;">
                                <div style="position:absolute;top:5%;left:25%;">获取验证码</div>
                            </div>
                        </div>*@
                        <input id="getCode" type="text" class="yzmb yzmbtn" value="获取验证码" readonly autocomplete="off" maxlength="6" />
                        @*<div id="getCode" class="yzmb yzmbtn" >获取验证码</div>*@
                        <input type="text" class="HiddenBox yzmb yzmbtnNone" value="" readonly autocomplete="off" maxlength="6" />
                        @*<div class="HiddenBox yzmbtnNone"></div>*@
                    </div>
                </td>                
            </tr>
            <tr style="height:8%;">
                <td>&nbsp;</td>
                <td colspan="2"><span id="spanMsg" style="color:red;"></span></td>
            </tr>
            <tr style="height:10%;">
                <td valign="center" class="TitTxt" style="padding-top:1%;">密 &nbsp;码</td>
                <td valign="top" colspan="2" style="padding-top:1%;">
                    @*<input id="txtPwd" type="text" class="Blockinput IptW black inputbg3" value="" autocomplete="off" />*@
                    <input id="pwd" type="password" class="Blockinput IptW  inputbg3" maxlength="12" autocomplete="off"  placeholder="输入登录密码" />
                </td>
            </tr>
            @*<tr style="height:20px;">
                <td>&nbsp;</td>
                <td colspan="2"><span id="regMsg" style="color:red;"></span></td>
            </tr>*@
            <tr style="height:13%;">
                <td valign="center" colspan="3" style="text-align:center;padding-top:5%;vertical-align:middle;">
                    @*<div id="btnReg" class="reg regbtnSX">立即注册</div>*@
                    <input type="text" id="btnReg" class="reg regbtnSX" value="立即注册" readonly autocomplete="off" maxlength="6" />
                </td>
            </tr>
                <tr style="height:auto;">
                <td colspan="3">
                    
                </td>
            </tr>
                </tbody>
        </table>
    </div>
    <div id="p2" class="HiddenBox" style="margin-left: 100px; margin-top: 10px;">
        <table width="180">
            <tr>
                <td valign="top" class="TitTxt">
                    <img src="http://static.emoney.cn/www/emfastock/img/cg.png" style="margin-bottom: 6px;" />
                </td>
            </tr>
            <tr>
                <td valign="top" class="TitTxt" align="center">
                    <div style="text-align: center; font-size: 13px;">登录后,您将<span style="color: Red;">免费获得30天操盘线功能</span>体验</div>
                    <div class="dlbtn" id="btnLogin" style="margin-left: 10px; display: inline;"></div>
                </td>
            </tr>
        </table>
    </div>
    <input type="hidden" id="hidSid" value="@ViewBag.Sid" />
    <input type="hidden" id="hidN" value="b570fe04448f2787e6857be7c5dc6f4eccd66ff6922a7b08094716a8c7ffe0cdaadb68c8716cf151cad9c99a2cce28b9182b1b3b52ae597847012be6ae62350bb3842c3af853f4ab68e086afcf9efd28785f39038f25aaff42e60b7bf424f3a8f5b33dd996836b4985ae7c52c003d8de249ab767af1eda382212200599135cbf" />
    <input type="hidden" id="hidE" value="010001" />
</body>
<script src="@SH.GetStaticFile("IStockClientStatic/js/istockfunc.js")" type="text/javascript"></script>
<script src="@SH.GetStaticFile("IStockClientStatic/js/rasall.js")" type="text/javascript"></script>
<script src="@SH.GetStaticFile("IStockClientStatic/ac/associate.js")" type="text/javascript"></script>
</html>
<script type="text/javascript">
    var www = "@Url.Content("~/")", countdownNum = 60, sendAccount = "", i = -1;//下拉序列起始;
    var maxrow = 5; //下拉裂变的最大值 0开始
    var isdelete = false; //是否有删除下拉的记录

    $(document).ready(function () {
        document.onselectstart = function () { return true; }
        document.onmousemove = function (e) { return true; }

        $("#account").focus(function () {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg1");
            }
            else {
                $(this).addClass("inputbg1");
            }
            $(this).addClass("Redinput").removeClass("Blockinput");
        });

        $("#account").blur(function () {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg1");
            }
            else {
                $(this).addClass("inputbg1");
            }
            $(this).addClass("Blockinput").removeClass("Redinput");
        });

        $("#account").keyup(function (e) {
            var account = $(this).val();

            if (account != "") {
                $(this).removeClass("inputbg1");
            }
            else {
                $(this).addClass("inputbg1");
            }

            if (account != "" && account.substr(0, 2) != "13" && account.substr(0, 2) != "14" && account.substr(0, 2) != "15" && account.substr(0, 2) != "18") {
                //ShowDownMenu(e);
            }
            else {
                $("#downmenu").hide();
            }
        });

        $("#code").focus(function () {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg2");
            }
            else {
                $(this).addClass("inputbg2");
            }
            $(this).addClass("Redinput").removeClass("Blockinput");
        });

        $("#code").blur(function () {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg2");
            }
            else {
                $(this).addClass("inputbg2");
            }
            $(this).addClass("Blockinput").removeClass("Redinput");
        });

        $("#code").keyup(function (e) {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg2");
            }
            else {
                $(this).addClass("inputbg2");
            }
        });

        $("#pwd").focus(function () {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg3");
            }
            else {
                $(this).addClass("inputbg3");
            }
            $(this).addClass("Redinput").removeClass("Blockinput");
        });

        $("#pwd").blur(function () {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg3");
            }
            else {
                $(this).addClass("inputbg3");
            }
            $(this).addClass("Blockinput").removeClass("Redinput");
        });

        $("#pwd").keyup(function (e) {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg3");
            }
            else {
                $(this).addClass("inputbg3");
            }
        });

        $("#btnLogin").hover(function () {
            $(this).addClass("dlbtnHover").removeClass("dlbtn")
        }, function () {
            $(this).addClass("dlbtn").removeClass("dlbtnHover");
        });

        $(".cancelbtn").hover(function () {
            $(this).addClass("cancelbtnHover").removeClass("cancelbtn")
        }, function () {
            $(this).addClass("cancelbtn").removeClass("cancelbtnHover");
        });

        $("#getCode").hover(function () {
            $(this).addClass("yzmbtnHover").removeClass("yzmbtn")
        }, function () {
            $(this).addClass("yzmbtn").removeClass("yzmbtnHover");
        });

        $("#btnReg").hover(function () {
            if (!$(this).hasClass("regbtnSX")) {
            $(this).addClass("regbtnHover").removeClass("regbtn");
            }
        }, function () {
            if (!$(this).hasClass("regbtnSX")) {
            $(this).addClass("regbtn").removeClass("regbtnHover");
            }
        });

        $("#btnReg").click(function () {
            if ($(this).hasClass("regbtnSX")) {
                return;
            }

            $("#spanMsg").html("");
            //$("#regMsg").html("");
            $("#spanMsg").css("color", "red");

            var account = $("#account").val();
            var code = $("#code").val();
            var pwd = $("#pwd").val();

            if (account == "") {
                $("#spanMsg").html("请输入常用手机号/邮箱");
                $("#account").focus();

                return false;
            }
            else if (account != sendAccount)
            {
                $("#spanMsg").html("手机号/邮箱输入错误");
                setSelection(document.getElementById('account'), $("#account").val().length);

                return false;
            }
            else if (code == "")
            {
                $("#spanMsg").html("请输入验证码");
                $("#code").focus();

                return false;
            }
            else if (code.length != 6)
            {
                $("#spanMsg").html("验证码格式错误");
                setSelection(document.getElementById('code'), $("#code").val().length);

                return false;
            }
            else if (pwd == "")
            {
                $("#spanMsg").html("请输入登录密码");
                $("#txtPwd").hide();
                $("#pwd").show();
                $("#pwd").focus();

                return false;
            }
            else if (pwd.length < 3) {
                $("#spanMsg").html("登录密码格式错误");
                setSelection(document.getElementById('pwd'), $("#pwd").val().length);

                return false;
            }
            else {
                var rsaAccount = rsaFunc(account);
                var rsaCode = rsaFunc(code);
                var rsaPwd = rsaFunc(pwd);
                window.external.OnCallLocalFunction(1, "", "");
                $.ajax({
                    type: "post",
                    url: www + "account/add",
                    data: { account: rsaAccount,code:rsaCode,pwd:rsaPwd,sid:$("#hidSid").val() },
                    datatype: "text",
                    success: function (data) {
                        if (data == "0") {
                            window.external.OnCallLocalFunction(0, account, pwd);
                        }
                        else {
                            window.external.OnCallLocalFunction(-1, "", "");
                        }
                    },
                    beforeSend: function () {
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                    }
                });
            }
        });

        $("#btnLogin").click(function () {
            ISTOCK_FUNC_ONREGISTERED($("#account").val(), $("#pwd").val());
        });

        $("#btnCancel").click(function () {
            ISTOCK_FUNC_ONUNREGISTER();
        });

        $(".yzmbtn").click(function () {
            $("#spanMsg").css("color", "red");
            var account = $("#account").val();

            if (account == "") {
                $("#spanMsg").html("请输入常用手机号/邮箱");
                $("#account").focus();
            }
            else {
                if (!account.match(/^\w+((-\w+)|(\.\w+))*\@@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) && !account.match(/^1[3|4|5|8][0-9]\d{4,8}$/)) {
                    $("#spanMsg").html("请输入有效的手机号/邮箱");
                    $("#account").focus();

                    setSelection(document.getElementById('account'), $("#account").val().length);
                }
                else {
                    var type = "";
                    if (account.match(/^\w+((-\w+)|(\.\w+))*\@@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/))
                    {
                        type = "2";
                    }
                    else if (account.match(/^1[3|4|5|8][0-9]\d{4,8}$/)) {
                        type = "1";
                    }

                    var rsaAccount = rsaFunc(account);
                    
                    if (rsaAccount != "")
                    {
                        $.ajax({
                            type: "post",
                            url: www + "account/send",
                            data: { account: rsaAccount,type:"1" },
                            datatype: "text",
                            success: function (data) {
                                switch (data) {
                                    case "1":
                                        sendAccount = account;

                                        $("#spanMsg").css("color", "#999");
                                        switch (type) {
                                            case "1":
                                                $("#spanMsg").html("短信已发送，请查收");
                                                break;
                                            case "2":
                                                $("#spanMsg").html("验证码已发送到邮箱，请查收");
                                                break;
                                            default:
                                                $("#spanMsg").html("发送成功");
                                                break;
                                        }
                                        
                                        $("#code").focus();
                                        $("#btnReg").addClass("regbtn").removeClass("regbtnSX");
                                        countdownNum = 60
                                        countdown();
                                        break;
                                    default:
                                        if (data != "" && data != "0") {
                                            $("#spanMsg").html(data);
                                        }
                                        else {
                                            $("#spanMsg").html("发送失败");
                                        }
                                        
                                        $("#getCode").show();
                                        $(".yzmbtnNone").hide();

                                        setSelection(document.getElementById('account'), $("#account").val().length);
                                        break;
                                }
                            },
                            beforeSend: function () {
                                $("#getCode").hide();
                                $(".yzmbtnNone").show();
                                $(".yzmbtnNone").val("发送中...");
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                window.external.OnCallLocalFunction(-1, "", "");
                                alert(XMLHttpRequest.status);
                            }
                        });
                    }
                }
            }
        });

    });

    function rsaFunc(text) {
        var rsa = new RSAKey();

        rsa.setPublic($("#hidN").val(), $("#hidE").val());
        var res = rsa.encrypt(text);

        if (res) {
            return linebrk(hex2b64(res), 64);
        }
        else {
            return "";
        }
    }

    function countdown() {
        $(".yzmbtnNone").val("倒计时 " + countdownNum);

        if (countdownNum > 0) {
            countdownNum = countdownNum - 1;

            set_cd = setTimeout(countdown, 1000);
        }
        else {
            $("#getCode").show();
            $(".yzmbtnNone").hide();
        }
    }

    function setSelection(editor, pos) {
        if (editor.setSelectionRange) {
            editor.focus();
            editor.setSelectionRange(pos, pos);
        } else if (editor.createTextRange) {
            var textRange = editor.createTextRange();
            textRange.collapse(true);
            textRange.moveEnd("character", pos);
            textRange.moveStart("character", pos);
            textRange.select();
        }
    }
</script>